const { createApp } = Vue

createApp({
    data() {
        return {
            selectedField: 'all',
            showModal: false,
            form: {
                type: 'offline',
                therapist: null,
                date: '',
                time: '',
                name: '',
                phone: '',
                description: ''
            },
            availableTimes: [
                { value: '09:00', label: '09:00 - 10:00' },
                { value: '10:00', label: '10:00 - 11:00' },
                { value: '11:00', label: '11:00 - 12:00' },
                { value: '14:00', label: '14:00 - 15:00' },
                { value: '15:00', label: '15:00 - 16:00' },
                { value: '16:00', label: '16:00 - 17:00' }
            ],
            fields: [
                { id: 'anxiety', name: '焦虑抑郁' },
                { id: 'relationship', name: '婚恋情感' },
                { id: 'family', name: '家庭关系' },
                { id: 'career', name: '职场压力' },
                { id: 'growth', name: '个人成长' }
            ],
            therapists: [
                {
                    id: 1,
                    name: '张医生',
                    title: '资深心理咨询师',
                    qualification: '国家二级心理咨询师',
                    experience: '15年咨询经验',
                    image: 'https://images.pexels.com/photos/5327585/pexels-photo-5327585.jpeg',
                    fields: ['焦虑抑郁', '婚恋情感'],
                    description: '从业15年，擅长焦虑抑郁、情绪管理、婚恋情感等领域的咨询。具有丰富的个案经验，擅长运用认知行为疗法、正念疗法等技术帮助来访者。',
                    specialties: ['抑郁症', '焦虑障碍', '情绪管理', '人际关系']
                },
                {
                    id: 2,
                    name: '李医生',
                    title: '心理治疗师',
                    qualification: '国家二级心理咨询师',
                    experience: '10年咨询经验',
                    image: 'https://images.pexels.com/photos/5327656/pexels-photo-5327656.jpeg',
                    fields: ['家庭关系', '个人成长'],
                    description: '专注于家庭治疗和个人成长领域，具有丰富的实践经验。擅长处理亲子关系、婚姻关系等家庭问题，帮助个人实现自我成长。',
                    specialties: ['家庭治疗', '亲子关系', '婚姻咨询', '自我提升']
                },
                {
                    id: 3,
                    name: '王医生',
                    title: '高级心理咨询师',
                    qualification: '国家一级心理咨询师',
                    experience: '12年咨询经验',
                    image: 'https://images.pexels.com/photos/5490276/pexels-photo-5490276.jpeg',
                    fields: ['职场压力', '个人成长'],
                    description: '擅长职场心理咨询，帮助来访者应对工作压力，提升职业表现。专注于职业发展规划、压力管理、领导力提升等领域。',
                    specialties: ['职业规划', '压力管理', '领导力培训', '团队建设']
                }
            ]
        }
    },
    computed: {
        filteredTherapists() {
            if (this.selectedField === 'all') {
                return this.therapists;
            }
            return this.therapists.filter(therapist =>
                therapist.fields.some(field =>
                    this.fields.find(f => f.id === this.selectedField)?.name === field
                )
            );
        },
        minDate() {
            const today = new Date()
            return today.toISOString().split('T')[0]
        },
        maxDate() {
            const today = new Date()
            const lastDayOfWeek = new Date(today)
            const daysTillEndOfWeek = 6 - today.getDay()
            lastDayOfWeek.setDate(today.getDate() + daysTillEndOfWeek)
            return lastDayOfWeek.toISOString().split('T')[0]
        },
        availableDates() {
            const dates = []
            const today = new Date()
            today.setHours(0, 0, 0, 0)
            const endDate = new Date(today)
            const daysTillEndOfWeek = 7 - today.getDay()
            endDate.setDate(today.getDate() + daysTillEndOfWeek)
            endDate.setHours(23, 59, 59, 999)

            let currentDate = new Date(today)
            while (currentDate <= endDate) {
                dates.push({
                    value: currentDate.toISOString().split('T')[0],
                    label: this.formatDate(currentDate)
                })
                currentDate = new Date(currentDate)
                currentDate.setDate(currentDate.getDate() + 1)
            }
            return dates
        }
    },
    methods: {
        formatDate(date) {
            const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
            const month = date.getMonth() + 1
            const day = date.getDate()
            const weekDay = weekDays[date.getDay()]
            return `${month}月${day}日 ${weekDay}`
        },
        filterByField(fieldId) {
            this.selectedField = fieldId;
        },
        showAppointment(therapist) {
            this.form.therapist = therapist;
            this.showModal = true;
        },
        closeModal() {
            this.showModal = false;
            this.resetForm();
        },
        resetForm() {
            this.form = {
                type: 'offline',
                therapist: null,
                date: '',
                time: '',
                name: '',
                phone: '',
                description: ''
            };
        },
        submitForm() {
            console.log('预约信息：', {
                ...this.form,
                therapistName: this.form.therapist.name
            });
            alert('预约提交成功！我们将尽快与您联系确认。');
            this.closeModal();
        }
    }
}).mount('#app') 